﻿#include "ToolButtonPropertyEditEntry.h"
#include <QToolButton>

#include "EnumEditEntry.h"
#include "BooleanEditEntry.h"

#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(ToolButton)

struct ToolButtonPropertyEditEntry::ToolButtonPropertyEditEntryPrivate {
    QPointer<QToolButton> object;

    QPointer<EnumEditEntry> entryPopupMode;
    QPointer<EnumEditEntry> entryToolButtonStyle;
    QPointer<BooleanEditEntry> entryAutoRaise;
    QPointer<EnumEditEntry> entryArrowType;
};

ToolButtonPropertyEditEntry::~ToolButtonPropertyEditEntry() { }

ToolButtonPropertyEditEntry::ToolButtonPropertyEditEntry(QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new ToolButtonPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
}

void ToolButtonPropertyEditEntry::setObject(void *object) {
    p->object = static_cast<QToolButton*>(object);
}

void ToolButtonPropertyEditEntry::onTick() {
    if(!p->object || !isVisible()) {
        return ;
    }

    p->entryPopupMode->setValue(p->object->popupMode());
    p->entryToolButtonStyle->setValue(p->object->toolButtonStyle());
    p->entryAutoRaise->setValue(p->object->autoRaise());
    p->entryArrowType->setValue(p->object->arrowType());
}

void ToolButtonPropertyEditEntry::initUi() {
    p->entryPopupMode = new EnumEditEntry;
    p->entryPopupMode->setMetaEnum(QMetaEnum::fromType<QToolButton::ToolButtonPopupMode>());
    appendChildEntry(p->entryPopupMode);

    p->entryToolButtonStyle = new EnumEditEntry;
    p->entryToolButtonStyle->setMetaEnum(QMetaEnum::fromType<Qt::ToolButtonStyle>());
    appendChildEntry(p->entryToolButtonStyle);

    p->entryAutoRaise = new BooleanEditEntry;
    appendChildEntry(p->entryAutoRaise);

    p->entryArrowType = new EnumEditEntry;
    p->entryArrowType->setMetaEnum(QMetaEnum::fromType<Qt::ArrowType>());
    appendChildEntry(p->entryArrowType);
}

void ToolButtonPropertyEditEntry::retranslateUi() {
    setTitle(tr("QToolButton"));
    p->entryPopupMode->setTitle(tr("popupMode"));
    p->entryToolButtonStyle->setTitle(tr("toolButtonStyle"));
    p->entryAutoRaise->setTitle(tr("autoRaise"));
    p->entryArrowType->setTitle(tr("arrowType"));
}
